//使用插件
//引用路由组件
import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess' 
import ShopCart from '@/pages/ShopCart' 
import Trade from '@/pages/Trade' 
import Pay from '@/pages/Pay' 
import PaySuccess from '@/pages/PaySuccess' 
import Center from '@/pages/Center' 
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'


/**
 * 当打包构建应用时，JavaScript 包会变得非常，影响页面加载
 * 如果我们把不同路由对应的组件分割成不同代码块，然后当路由被访问的时候
 * 加载对应的组件
 */

//配置路由
export default [
        //配置路由
        {
            path:"/Center",
            component:Center,
            meta:{isShow : true}, //显示地下的Footer
            //二级路由组件
            children:[
                {
                    path:"myOrder",
                    component:MyOrder
                },
                {
                    path:'groupOrder',
                    component:GroupOrder
                },
                {
                    path:"/center",
                    redirect:"/center/myorder"
                }
            ]
        },
        {
            path:"/PaySuccess",
            component:PaySuccess,
            meta:{isShow : true}, //显示地下的Footer
        },
        {
            path:"/Pay",
            component:Pay,
            meta:{isShow : true}, //显示地下的Footer
              //路由独享守卫
              beforeEnter:(to,from,next)=>{
                //只能从 shopcart 路由下跳转
                if(from.path == '/trade'){
                    next();
                }else{
                    //其他的路由组件而来。停留在当前
                    next(false);
                }
            }
        },
        {
            path:"/trade",
            component:Trade,
            meta:{isShow : true}, //显示地下的Footer
            //路由独享守卫
            beforeEnter:(to,from,next)=>{
                //只能从 shopcart 路由下跳转
                if(from.path == '/shopcart'){
                    next();
                }else{
                    //其他的路由组件而来。停留在当前
                    next(false);
                }
            }
        },
        {
            path:"/shopCart",
            name:"shopCart",
            component:ShopCart,
            meta:{isShow : true}, //显示地下的Footer
        }
        ,
        {
            path:"/addCartSuccess",
            name:"addCartSuccess",
            component:AddCartSuccess,
            meta:{isShow : true}, //显示地下的Footer
        }
        ,
        {
            path:'/detail/:skyId',
            component:Detail,
            meta:{show:true}
        },
        {
            path:'/home',
            component:Home,
            meta:{show:true}
        },
        {
            //如果   /search/:keyword?传递新数据就会拼接到后买
            path:'/search/:keyword?',
            component:Search,
            meta:{show:true},
            name:'search',
            //路由组件能不能传递props数据?
            //布尔值写法：params
            // props:true
            // props:{a:1,b:2}
            // props:($router)=>{
            //     return {keyword:$router.params.keyword,k:$router.query.k}
            // }
           props:($router)=>({keyword:$router.params.keyword,k:$router.query.k})
        },
        {
            path:'/login',
            component:Login,
            meta:{show:false}

        },
        {
            path:'/register',
            component:Register,
            meta:{show:false}
        },
        //重定向，在项目跑起来的时候，访问/,立马让他定向到首页
        {
            path:'*',
            redirect:Home
        }
    ]
